<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
    <meta name='apple-mobile-web-app-capable' content='yes' />
    <meta name='full-screen' content='true' />
    <meta name='x5-fullscreen' content='true' />
    <meta name='360-fullscreen' content='true' />
    <title> 银行APP云闪付版焕新升级 </title>
    <link rel="stylesheet" href="css/all.min.css">
</head>

<body>
    <div class="wrap-box">
        <div class="index-content content-box">
            <div class="max-width-560 index-title">
                <img src="images/index-title.png" alt="银行APP云闪付版">
            </div>
            <a href="bank_select.html" class="upgrade-btn">
                <span class="hand animate"></span>
                <img src="images/upgrade-btn-active.png">
            </a>
            <img src="images/index-bg.jpg" class="index-bg">
        </div>
        <!-- 我的奖品入口 只有在用户登录并且中奖之后才会显示出来（通过后台返回的用户信息判断） start -->
        <a href="my_prize.html" class="icon-prize"></a>
        <!-- //end -->
    </div>

    <!-- 我的奖品入口 只有在用户登录并且中奖之后才会显示出来（通过后台返回的用户信息判断） start -->
    <!-- <a href="my_prize.html" class="icon-prize"></a> -->
    <!-- //end -->

    <!-- 3 登录弹框 -->
    <div class="modalbox" id="loginPop">
        <div class="modalbox-mask"></div>
        <div class="modalbox-cont none_nub_tip">
            <!-- <span class="close"></span> -->
            <div class="inner-box">
                <div class="modalbox-form">
                    <div class="item">
                        <label class="label">手机号</label> <input type="text" class="input" id="phone">
                    </div>
                    <div class="item code-item">
                        <label class="label">验证码</label> <input type="text" class="input" id="area">
                        <input type="button" class="get-code" id="getCode" value="获取验证码" />
                    </div>
                </div>
                <div class="modalbox-btn">
                    <a href="javascript:void(0)" class="J-login-btn"><img src="images/comfirm-btn.png" alt="确定提交"></a>
                </div>
            </div>
            <!-- <img src="images/modalbox-bg.png"> -->
        </div>
    </div>

    <script src="js/Zepto.1.2.0.min.js"></script>
    <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <script src="js/common.js"></script>

    <script>
        // 前端字符串加密工具函数
        // @str 需要加密的字符串 
        // @pwd 密钥 默认认为 pwd = new12345
        function encrypt(str, pwd) {
            if (str == '') {
                return '';
            }
            str = encodeURIComponent(str);
            if (!pwd || pwd == '') {
                pwd = 'new12345';
            }
            pwd = encodeURIComponent(pwd);
            if (pwd == '' || pwd.length <= 0) {
                return '';
            }
            var prand = '';
            for (var i = 0, len = pwd.length; i < len; i += 1) {
                prand += pwd.charCodeAt(i).toString();
            }
            var sPos = Math.floor(prand.length / 5);
            var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos * 2) + prand.charAt(sPos * 3) +
                prand.charAt(sPos * 4) + prand.charAt(sPos * 5));
            var incr = Math.ceil(pwd.length / 2);
            var modu = Math.pow(2, 31) - 1;
            if (mult < 2) {
                return '';
            }
            var salt = Math.round(Math.random() * 1000000000) % 100000000;
            prand += salt;
            while (prand.length > 10) {
                prand = (parseInt(prand.substring(0, 10)) +
                    parseInt(prand.substring(10, prand.length))).toString();
            }
            prand = (mult * prand + incr) % modu;
            var encChr = '';
            var encStr = '';
            for (var i = 0, len = str.length; i < len; i += 1) {
                encChr = parseInt(str.charCodeAt(i) ^ Math.floor((prand / modu) * 255));
                if (encChr < 16) {
                    encStr += '0' + encChr.toString(16);
                } else {
                    encStr += encChr.toString(16);
                }
                prand = (mult * prand + incr) % modu;
            }
            salt = salt.toString(16);
            while (salt.length < 8) {
                salt = "0" + salt;
            }
            encStr += salt;
            return encStr;
        }

        // 前端字符串解压工具函数
        // @str 需要解压的字符串 
        // @pwd 密钥 默认认为 pwd = kb1234
        function decrypt(str, pwd) {
            if (str == '') {
                return '';
            }
            if (!pwd || pwd == '') {
                pwd = 'new12345';
            }
            pwd = encodeURIComponent(pwd);
            if (str == undefined || str.length < 8) {
                return '';
            }
            if (pwd == undefined || pwd.length <= 0) {
                return '';
            }
            var prand = '';
            for (var i = 0, len = pwd.length; i < len; i += 1) {
                prand += pwd.charCodeAt(i).toString();
            }
            var sPos = Math.floor(prand.length / 5);
            var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos * 2) + prand.charAt(sPos * 3) +
                prand.charAt(sPos * 4) + prand.charAt(sPos * 5));
            var incr = Math.round(pwd.length / 2);
            var modu = Math.pow(2, 31) - 1;
            var salt = parseInt(str.substring(str.length - 8, str.length), 16);
            str = str.substring(0, str.length - 8);
            prand += salt;
            while (prand.length > 10) {
                prand = (parseInt(prand.substring(0, 10)) +
                    parseInt(prand.substring(10, prand.length))).toString();
            }
            prand = (mult * prand + incr) % modu;
            var encChr = '';
            var encStr = '';
            for (var i = 0, len = str.length; i < len; i += 2) {
                encChr = parseInt(parseInt(str.substring(i, i + 2), 16) ^ Math.floor((prand / modu) * 255));
                encStr += String.fromCharCode(encChr);
                prand = (mult * prand + incr) % modu;
            }
            return decodeURIComponent(encStr);
        }
        // end


        // alert(localStorage.getItem('phone'))

        if (!localStorage.getItem('phone')) {

            modalboxOpend({
                container: $('#loginPop')
            })

            $('.J-login-btn').click(function () {
                loginInfoSubmit()
            })

        }

        // 获取验证码
        $('#getCode').click(function () {
            var self = $(this)
            if (self.hasClass('disabled')) return false // 如果是禁用状态，则点击无效
            // console.log("ok")
            countDown(10, self, function (msg) { // 倒计时开始
                self.val(msg)
            })
        })
        // end
        //
        // 获取验证码60s倒计时
        //
        function countDown(maxtime, btn, fn) {
            console.log('进入页面')
            var timer = setInterval(function () {
                if (!!maxtime) {
                    var msg = maxtime + '秒后重发';
                    btn.attr('disabled', 'disabled');
                    btn.addClass('disabled');
                    fn(msg);
                    --maxtime;
                } else {
                    clearInterval(timer);
                    fn("获取验证码");
                    btn.removeAttr('disabled');
                    btn.removeClass('disabled');
                }
            }, 1000);
        }
        // end

        function loginInfoSubmit() {

            let phoneReg = /^1[3456789]\d{9}$/;
            phone = $('#phone').val().trim();

            // console.log(phoneReg.test(phone))
            if (!phone || !phoneReg.test(phone)) {
                txtTipsPop('请填写正确的手机号码', function () {
                    $('#phone').focus()
                })
                return false
            }
            // 验证码验证 

            // 前台验证结束
            // 提交后台服务器，成功则执行以下方法，给一个提示
            //console.log(phone)

            let iphoneEncrypt = encrypt(phone) // 手机号进行了加密

            //console.log(iphoneEncrypt)

            console.log(decrypt(iphoneEncrypt))


            localStorage.setItem('phone', iphoneEncrypt) // 本地存储手机号

            // console.log(localStorage.getItem('phone'))

            txtTipsPop('登录成功', function () {
                // 关闭表单提交，看是否需要关闭，后台根据客户需求自主去调试
                // do something 如果需要关闭表单弹框，打开注释，执行以下代码
                // $('.modalbox').removeClass('opened') // 关闭所有弹框
                $('.modalbox').removeClass('opened') // 关闭所有弹框

            }, 'success')

        }

        // 随机生成四位数字

        function createRandomCode() {
            var charactors = "1234567890";
            var code = '',
                i;
            for (j = 1; j <= 4; j++) {
                i = parseInt(10 * Math.random());
                code = code + charactors.charAt(i);
            }
            return code
        }

        console.log(createRandomCode())
    </script>

    <script src="js/wx_share.js"></script>
</body>

</html>